package com.cloud.point.javase;

import lombok.extern.slf4j.Slf4j;

/**
 * 静态代理
 *
 * @author 24373
 * @version 1.0
 * @date 2024-07-04 16:24
 */
@Slf4j
public class TestStaticProxy {
    public static void main(String[] args) {
        ClothFactoryProxy clothFactory = new ClothFactoryProxy(new NikeFactory());
        clothFactory.makeProduct();
    }
}

@Slf4j
class NikeFactory implements StaticFactory {
    @Override
    public void makeProduct() {
        log.info("静态生产nike衣服");
    }
}

/**
 * 代理类
 * 对其它实现类做增强
 * 代理实现了需要代理的代理类接口，从一开始就知道传入对象是什么。所以它是静态的
 */
@Slf4j
class ClothFactoryProxy implements StaticFactory {
    private final StaticFactory factory;

    public ClothFactoryProxy(StaticFactory factory) {
        this.factory = factory;
    }

    @Override
    public void makeProduct() {
        log.info("代理工厂生产前");
        factory.makeProduct();
        log.info("代理工厂生产后");
    }

}

interface StaticFactory {
    void makeProduct();

}
